
import java.io.IOException;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Leon
 */
public class Wave extends Sprite implements Runnable{

        private int CurrentFrame = 0;
        private boolean Running;

        public Wave(int X,int Y) throws IOException
        {
            super(Image.createImage("/resource/wave_attack2.png"),30,30);
            defineReferencePixel(15,15);
            setRefPixelPosition(X, Y);

            Running = true;
            Thread T = new Thread(this);
            T.start();
        }

        public void NextFrame(){
            setFrame(CurrentFrame);
            CurrentFrame ++;
            if(CurrentFrame == 6)
            {
                try {
                Thread.sleep(20);
                } catch (InterruptedException ex) {}
                Remove();
            }

        }

        private void Remove(){
            // Tự hủy
            Running = false;
            GameManager.Waves.remove(this);
        }

        public void run(){
            while(Running)
            {
                NextFrame();
                try {
                Thread.sleep(50);
                } catch (InterruptedException ex) {}
            }
        }
}
